package top.starmc.starpet.entity.ai;

import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.PathfinderGoal;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import top.starmc.starpet.config.Config;
import top.starmc.starpet.entity.EntityPet;

public class PetFollowOwner extends PathfinderGoal {
    EntityPet entity;
    EntityPlayer owner;

    public PetFollowOwner(EntityPet entity, Player p) {
        this.entity = entity;
        owner = ((CraftPlayer) p).getHandle();
    }

    @Override
    public boolean a() {
        return entity.h(owner) > 4;
    }

    @Override
    public boolean b() {
        return entity.h(owner) > Config.getFollowDistance();
    }

    @Override
    public void d() {
        entity.getNavigation().p();
    }

    @Override
    public void e() {
        if (entity.h(owner) > Config.getTeleportDistance() && owner.onGround) {
            entity.setPosition(owner.locX, owner.locY, owner.locZ);
        } else {
            entity.getNavigation().a(owner, 0.5);
        }
    }
}
